<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>个人收入</title>
		<link rel="stylesheet" href="../../layuiadmin/js/finance/js/bootstrap/css/bootstrap.min.css" />
		<script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.min.js" ></script>
		<script type="text/javascript" src="../../layuiadmin/js/finance/js/bootstrap/js/bootstrap.js" ></script>
		<script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.cookie.js"></script>
		<script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.jqprint-0.3.js"></script>
		<script src="http://www.jq22.com/jquery/jquery-migrate-1.2.1.min.js";></script>
		<script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.table2excel.js"></script>
		<script>
			$(document).ready(function () {
				$("#divshow").hide();
			});
			//时间检索
			function show() {
				list();
				$("#divshow").show();
				var one=0;
				tabshow(one);
			}
			//近一个月查询
			function onemonth() {
				list();
				$("#divshow").show();
				var one=1;
				tabshow(one);
			}
			//近三个月查询
			function threemonth() {
				list();
				$("#divshow").show();
				var one=3;
				tabshow(one);
			}
			//近六个月查询
			function sixmonth() {
				list();
				$("#divshow").show();
				var one=6;
				tabshow(one);
			}
			//近一年查询
			function oneyear() {
				list();
				$("#divshow").show();
				var one=12;
				tabshow(one);
			}
			function tabshow(one) {
				//获取当前时间
				var myDate = new Date();
				var year=myDate.getFullYear();
				var month=myDate.getMonth()+1;
				var date=myDate.getDate();
				if(date<10){
					date="0"+date;
				}
				if(month<10){
					month+="0";
				}
				var now=year+'-'+month+"-"+date;
				//结束时间
				var enddate=$("#enddate").val();
				//开始时间
				var startdate = $("#startdate").val();
				if(one<12&&one>0){
					enddate=now;
					var months=month-one;
					if(months<10){
						months="0"+months;
					}
					var onenow = year + '-' + months + "-" + date;
					startdate=onenow;
				}else if(one>=12&&one<24){
					//现在时间
					enddate=now;
					var onenow = year-1 + '-' + month + "-" + date;
					startdate=onenow;
					enddate=now;
				}else if(one==0){
					enddate=$("#enddate").val();
					startdate = $("#startdate").val();
				}
                $.post("http://localhost:8080/financeIncomeController/incomelist",
						{"startdate":startdate,"enddate":enddate},
						function (msg) {
                    //律师日期内创收
                    var tab = $("#tab1");
                    if(msg.length==0){
                        $("#tab1  tr:not(:first)").remove();
                        var tr=$("<tr></tr>");
                        var td=$("<td colspan='7'>没有相关数据</td>");
                        tr.append(td);
                        tab.append(tr);
						var enddate1=$("#enddate").val("");
						var startdate1 = $("#startdate").val("");
                    }else {
                        $("#tab1  tr:not(:first)").remove();
                        var sum = 0;
                        var tr1 = $("<tr></tr>");
                        for (var i = 0; i < msg.length; i++) {
                            //将T实际转换
                            var myDate = new Date(msg[i].collectionDate);
                            var year=myDate.getFullYear();
                            var month=myDate.getMonth()+1;
                            var date=myDate.getDate();
                            var now=year+'-'+month+"-"+date;
                            var tr = $("<tr></tr>");
                            var td1 = $("<td>" + msg[i].caseId.mainLawyer.empName + "</td>");
                            var td2 = $("<td>" + msg[i].caseId.caseId + "</td>");
                            var td3 = $("<td>" + msg[i].caseId.clientId.clientName + "</td>");
                            var td4 = $("<td>" + msg[i].caseId.oppositeId.clientName + "</td>");
                            var td5 = $("<td>" + now + "</td>");
                            var td6 = $("<td>" + msg[i].collectionMoney + "</td>");
                            var td7 = $("<td>" + msg[i].remark + "</td>");
                            tr.append(td1);
                            tr.append(td2);
                            tr.append(td3);
                            tr.append(td4);
                            tr.append(td5);
                            tr.append(td6);
                            tr.append(td7);
                            tab.append(tr);
                        }
                    }
                    //律师日期内创收提成
                    var tab2 = $("#tab2");
                    if(msg.length==0){
                        $("#tab2  tr:not(:first)").remove();
                        var tr=$("<tr></tr>");
                        var td=$("<td colspan='7'>没有相关数据</td>");
                        tr.append(td);
                        tab2.append(tr);
                    }else {
                        $("#tab2  tr:not(:first)").remove();
                        var sum = 0;
                        var tr1 = $("<tr></tr>");
                        for (var i = 0; i < msg.length; i++) {
                            //将T实际转换
                            var myDate = new Date(msg[i].collectionDate);
                            var year=myDate.getFullYear();
                            var month=myDate.getMonth()+1;
                            var date=myDate.getDate();
                            var now=year+'-'+month+"-"+date;
                            var tr = $("<tr></tr>");
                            var td1 = $("<td>" + msg[i].caseId.mainLawyer.empName + "</td>");
                            var td2 = $("<td>" + msg[i].caseId.caseId + "</td>");
                            var td3 = $("<td>" + msg[i].caseId.clientId.clientName + "</td>");
                            var td4 = $("<td>" + msg[i].caseId.oppositeId.clientName + "</td>");
                            var td5 = $("<td>" + msg[i].creatIncome+ "</td>");
                            var td6 = $("<td>" + msg[i].actualMoney + "</td>");
                            tr.append(td1);
                            tr.append(td2);
                            tr.append(td3);
                            tr.append(td4);
                            tr.append(td5);
                            tr.append(td6);
                            tab2.append(tr);
                            var actualMoney=msg[i].actualMoney;
                            var actualMoneys=$("#actualMoney").text(msg[i].actualMoney);
                            var cookie=$.cookie("redisName");
                            $.post("http://localhost:8080/financeIncomeController/user", {"username":cookie}, function (msg) {
                                $.post("http://localhost:8080/financeIncomeController/empincome",
                                    {"empid":msg.hrEmp.empId},
                                    function (data) {
                                        for(var j=0;j<data.length;j++){
                                            //基本工资
                                            var basicSalarys=$("#basicSalary").text(data[j].basicSalary);
                                            //其他收入
                                            var alljia=data[j].levelSalary+data[j].managmentCost+data[j].accumulationFund+data[j].persionInsurance+data[j].overtimeWage+data[j].yearendonus;
                                            var otherincomes=$("#otherincome").text(alljia);
                                            //其他支出
                                            var otherouts=$("#otherout").text(((data[j].incomeTax+data[j].attendanceEdduction)*(-1)));
                                            //总结
                                            var alls=(data[j].basicSalary+alljia+((data[j].incomeTax+data[j].attendanceEdduction)*(-1))+actualMoney);
                                            var all=$("#all").text(alls);
                                        }
                                    });
                            });
                        }
                    }
                });

            }
			function list(){
				var cookie=$.cookie("redisName");
				$.post("http://localhost:8080/financeIncomeController/user", {"username":cookie}, function (msg) {
				    var user=$("#user").text(msg.hrEmp.empName);
                    var empid=$("#empid").text(msg.hrEmp.empId);
					//获取当前时间
					var myDate = new Date();
					var year=myDate.getFullYear();
					var month=myDate.getMonth()+1;
					var date=myDate.getDate();
					var now=year+'-'+month+"-"+date;
					var nowtime=$("#nowdate").text(now);
				});
			}
			//打印
			function print() {
				$("#alls").jqprint();
			}
			//导出
			function out() {
				$("#alls").table2excel({
					//table2excel插件的可用配置参数有：
					exclude: ".noExl",//   exclude：不被导出的表格行的CSS class类。
					name: "Excel Document Name",//   name：导出的Excel文档的名称
					filename: "myFileName",//   filename：Excel文件的名称。
					exclude_img: true,//   exclude_img：是否导出图片。
					exclude_links: true,//   exclude_links：是否导出超链接
					exclude_inputs: true//    exclude_inputs：是否导出输入框中的内容
				});
			}
		</script>
	</head>
	<body>
	<div class="container-fluid">
		<form class="form-horizontal form-inline" >
			<div class="row" style="margin-top: 15px">
				<div class="col-lg-12">
					<div class="col-lg-6">
						<label>日期:</label>
						<input type="date" class="form-control" id="startdate"/>
						<input type="date" class="form-control" id="enddate"/>
						<button type="button" class="btn btn-success" onclick="show()">检索</button>
					</div>
					<div class="col-lg-6">
						<input type="button" class="btn btn-default" id="one" onclick="onemonth()" value="近一个月"/>
						<input type="button" class="btn btn-default" id="three" onclick="threemonth()" value="近三个月"/>
						<input type="button" class="btn btn-default" id="six" onclick="sixmonth()" value="近半年"/>
						<input type="button" class="btn btn-default" id="onyear" onclick="oneyear()" value="近一年"/>
					</div>
				</div>
			</div>
			<div style="margin-top: 15px" id="alls">
				<div class="col-lg-12" id="divshow">
					<p align="center"><font style="font-size: 25px"><strong>律师事务所执业人员财务清单</strong></font></p>
                    <font style="font-size: 20px"><strong>执业人员:&nbsp&nbsp&nbsp</strong></font><span id="user"></span>
					<font style="font-size: 20px"><strong>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp日期:</strong></font><span id="nowdate"></span>
					<br><br>
					<font style="font-size: 20px"><strong>律师日期内创收</strong></font>
					<table class="table table-hover table-bordered" style="text-align: center" id="tab1">
						<tr style="font-weight: bold">
							<td>承办律师</td>
							<td>案号</td>
							<td>委托人</td>
							<td>对方当事人</td>
							<td>收款日期</td>
							<td>收款金额</td>
							<td>备注</td>
						</tr>
					</table>
					<br>
					<font style="font-size: 20px"><strong>律师日期内创收提成</strong></font>
					<table class="table table-hover table-bordered" style="text-align: center" id="tab2">
						<tr style="font-weight: bold">
							<td>承办律师</td>
							<td>案号</td>
							<td>委托人</td>
							<td>对方当事人</td>
							<td>创收金额</td>
							<td>实际提成</td>
						</tr>
					</table>
					<br>
					<font style="font-size: 20px"><strong>实际收入</strong></font>
					<br><br>
					<font style="font-size: 15px">基本工资(+):</font><span id="basicSalary"></span>
					<br><br>
					<font style="font-size: 15px">案件提成(+):</font><span id="actualMoney"></span>
					<br><br>
					<font style="font-size: 15px">其他收入(+):</font><span id="otherincome"></span>
					<br><br>
					<font style="font-size: 15px">其他支出(-):</font><span id="otherout"></span>
					<br><br>
					<font style="font-size: 20px"><strong>合计收入:</strong></font><span id="all"></span>
					<br><br>
					<div align="center">
						<button type="button" class="btn btn-success" onclick="out()">导出</button>
						<button type="button" class="btn btn-success" onclick="print()">打印</button>
					</div>
				</div>
			</div>
		</form>
	</div>
	</body>
</html>